package cool.zhoujie.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;

import java.util.List;

import cool.zhoujie.MyApplication;
import cool.zhoujie.R;
import cool.zhoujie.gson.Data_Rec;

public class DailyAdapter extends ArrayAdapter<Data_Rec> {

    private int resourceId;

    public DailyAdapter(@NonNull Context context, int resource, @NonNull List<Data_Rec> objects) {
        super(context, resource, objects);
        this.resourceId = resource;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        Data_Rec rec = getItem(position);
        View view;
        if (convertView == null) {
            view = LayoutInflater.from(getContext()).inflate(resourceId, parent, false);
        } else {
            view = convertView;
        }
        ImageView songPic = view.findViewById(R.id.item_songPic);
        TextView songName = view.findViewById(R.id.item_songName);
        TextView artistName = view.findViewById(R.id.item_artistName);
        //圆角化
        Glide.with(MyApplication.getContext())
                .load(rec.pic_big)
                .apply(RequestOptions.bitmapTransform(new RoundedCorners(20)))
                .into(songPic);
        songName.setText(rec.title);
        artistName.setText(rec.author);
        return view;
    }
}
